<html>

<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
  <link rel="stylesheet" title="Default" href="http://acm.math.spbu.ru/~sk1/colorer/my.css">

  <script src="http://acm.math.spbu.ru/~sk1/colorer/highlight.js"></script>
  <script src="http://acm.math.spbu.ru/~sk1/colorer/cpp.js"></script>
  <script>hljs.initHighlightingOnLoad();</script>
</head>

<body>

<pre><code>
/**
 * Author: Sergey Kopeliovich (Burunduk30@gmail.com5
 * Date: 2013.10.18
 */

#include &lt;cstdio&gt;
#include &lt;cassert&gt;
#include &lt;cstring&gt;
#include &lt;algorithm&gt;

using namespace std;

#define forn(i, n) for (int i = 0; i &lt; (int)(n); i++)
#define fornd(i, n) for (int i = (int)(n) - 1; i &gt;= 0; i--)

const char *days[] = {"MON", "TUE", "WED", "THU", "FRI", "SAT", "SUN"};

const int N = 300 + 10;

int n, m, k, a[N][N], inv[7];
int an, ind[N], x[N];

int get( char *s )
{
  int i = 0;
  while (i &lt; 7 && strcmp(s, days[i]))
    i++;
  assert(i &lt; 7);
  return i;
}

int ans( int x )
{
  return x &lt; 3 ? x + 7 : x;
}

int cor( int &a )
{
  return a = (a % 7 + 7) % 7;
}

void solve()
{
  int fail = 0;
  an = 0;
  assert(n &lt;= N && m &lt;= N);
  while (m--)
  {
    char beg[40], end[40];
    assert(scanf("%d%s%s", &k, beg, end) == 3);
    a[an][n] = get(end) - get(beg) + 1;
    forn(j, n)
      a[an][j] = 0;
    while (k--)
    {
      int x;
      assert(scanf("%d", &x) == 1 && 1 &lt;= x && x &lt;= n), x--;
      a[an][x]++, a[an][x] %= 7;
    }
    forn(j, an)
      if (a[an][ind[j]] % 7 != 0)
      {
        int koef = a[an][ind[j]] * inv[a[j][ind[j]]];
        forn(t, n + 1)
          a[an][t] -= koef * a[j][t], a[an][t] %= 7;
      }
    forn(j, n + 1)
      cor(a[an][j]);

    int x = 0;
    while (x &lt; n + 1 && !a[an][x])
      x++;
    
    if (x == n)
      fail = 1;
    if (x &lt; n)
      ind[an++] = x;
  }
  if (fail)
  {
    puts("Inconsistent data.");
    return;
  }
  if (an &lt; n)
  {
    puts("Multiple solutions.");
    return;
  }
  fornd(i, n)
  {
    int &X = x[ind[i]];
    X = a[i][n];
    for (int j = i + 1; j &lt; n; j++)
      X -= x[ind[j]] * a[i][ind[j]], x[i] %= 7;
    X *= inv[a[i][ind[i]]];
    cor(X);
  }
  forn(i, n)
    printf("%d%c", ans(x[i]), " \n"[i == n - 1]);
}

int main()
{
  forn(i, 7)
    forn(j, 7)
      if ((i * j) % 7 == 1)
        inv[i] = j;

  int tmp;
  while ((tmp = scanf("%d%d", &n, &m)) == 2 && (n || m))
    solve();
  return 0;
}

</code></pre>

</body>
</html>

<font style="visibility:hidden">
